package com.cslc.wechat.common.action;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{
	public final Logger log = Logger.getLogger(getClass());
	
	protected String errorMsg;//错误信息
	
	/**
	 * ServletActionContext
	 */
	protected ActionContext actionContext() {
		return ActionContext.getContext();
	}

	/**
	 * HttpServletRequest
	 */
	protected HttpServletRequest request() {
		return (HttpServletRequest) actionContext().get(
				ServletActionContext.HTTP_REQUEST);
	}

	/**
	 * HttpServletResponse
	 */
	protected HttpServletResponse response() {
		return (HttpServletResponse) actionContext().get(
				ServletActionContext.HTTP_RESPONSE);
	}

	/**
	 * HttpSession
	 */
	protected HttpSession session() {
		return request().getSession();
	}

	/**
	 * ServletContext
	 */
	protected ServletContext application() {
		return (ServletContext) actionContext().get(
				ServletActionContext.SERVLET_CONTEXT);
	}
	
	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
}
